import 'package:flutter/material.dart';
import 'package:ytbusiness/config/url.dart';
import 'package:ytbusiness/models/incident_list.dart';
import 'package:ytbusiness/models/insurance_model.dart';
import 'package:ytbusiness/models/scout_order_model.dart';
import 'package:ytbusiness/models/scout_order_list.dart';
import 'package:ytbusiness/repository/http.dart';
import 'package:ytbusiness/utils/helper.dart';

///勘察员数据类
class ScoutRequest {
  /// 勘察员登录
  Future scoutLogin({
    BuildContext context,
    Map<String, dynamic> data,
  }) async {
    Map<String, dynamic> map =
        await Http().get(Url.scoutLogin, context: context, data: data)
            as Map<String, dynamic>;
    if (map != null && map.isNotEmpty) {
      if (map["code"] == 1001) {
        return map;
      }
      toast("${map['message']}");
    }
    return Future.error("接口请求失败");
  }

  /// 保险公司信息
  static Future<InsuranceModel> insuranceInfo({
    BuildContext context,
    Map<String, dynamic> data,
  }) async {
    Map<String, dynamic> map =
        await Http().get(Url.insuranceCompany, context: context, data: data)
            as Map<String, dynamic>;
    if (map != null && map.isNotEmpty) {
      if (map["code"] == 1001) {
        return InsuranceModel.fromJson(map);
      }
      toast("${map['message']}");
    }
    return Future.error("接口请求失败");
  }

  ///勘察员事件列表
  static Future<IncidentList> scoutOrder({
    BuildContext context,
    Map<String, dynamic> data,
  }) async {
    Map<String, dynamic> map =
        await Http().get(Url.scoutOrderList, context: context, data: data)
            as Map<String, dynamic>;
    if (map != null && map.isNotEmpty) {
      if (map["code"] == 1001) {
        return IncidentList.fromJson(map);
      }
      toast("${map['message']}");
    }
    return Future.error("接口请求失败");
  }

  ///勘察员订单列表
  static Future<ScoutOrderList> scoutOrderList({
    BuildContext context,
    Map<String, dynamic> data,
  }) async {
    Map<String, dynamic> map =
        await Http().get(Url.scoutOrder, context: context, data: data)
            as Map<String, dynamic>;
    if (map != null && map.isNotEmpty) {
      if (map["code"] == 1001) {
        return ScoutOrderList.fromJson(map);
      }
      toast("${map['message']}");
    }
    return Future.error("接口请求失败");
  }
}
